﻿$(document).ready(function () { // Added by 'Imran Gani' 23-Jul-2013, for the gap on top
    if ($("#ctl00_ContentPlaceHolder3_lbl_message").html() == "")
        $("#ctl00_ContentPlaceHolder3_lbl_message").css("display", "none");
    else
        $("#ctl00_ContentPlaceHolder3_lbl_message").css("display", "block");
});

function DeleteClick(strDelPK, intCurrentPage) {

    if (document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteafrowid") != null) {

        document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteafrowid").value = strDelPK;
        //alert(strDelPK);
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId") != null) {

        document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = intCurrentPage;
        //alert(intCurrentPage);
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteClick") != null) {
        //alert("delete clicked");
        document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteClick").value = "1";
    }
}
function UpdateMK(strMK) {
    if (document.getElementById("ctl00_ContentPlaceHolder3_hihMKafrowid") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hihMKafrowid").value = strMK;
    }
}
function UpdateDeletePageset(strpgsid) {
    if (document.getElementById("ctl00_ContentPlaceHolder3_hihdeletepagesetid") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hihdeletepagesetid").value = strpgsid;
    }
}

function FormLoadDisable() {
    //alert("am Form Load Disable");
    if (document.getElementById("ct100_ContentPlaceHolder3_btnSave") != null) {
        javascript: disableThis('ctl00_ContentPlaceHolder3_btnSave', 'Saving...');
    }

    if (document.getElementById("ct100_ContentPlaceHolder3_btnUpdate") != null) {
        javascript: disableThis('ctl00_ContentPlaceHolder3_btnUpdate', 'Saving...');
    }
}   

/***************** Section as Tabs ******************/ // Implemented by 'Imran Gani' on 31-May-2013
function LoadSectionsAsTabs() {
    var vm_loc = document.location.href;
    if (vm_loc.toLowerCase().indexOf("dynamicscreen.aspx") > -1) {
        if ($("#ctl00_ContentPlaceHolder3_hfSectionsAsTabs").val().toLowerCase() == "true") {
            
            var DivTable = document.createElement("div");
            DivTable.id = "basic_details";
            
            var ullist = "";
            var BasicRow = $("tr[id^=ctl00_ContentPlaceHolder3_pe_sectionheader___MB_EMPTY_SECTION]");
            if (BasicRow.length > 0)
                ullist += "<li><a href=\"#basic_details\">Basic Details</a></li>";

            var Table = document.createElement("table");
            Table.width = "100%";
            var TableBody = document.createElement('tbody');

            var TempDiv = document.createElement("div");

            var TableRow = $("tr[id^=ctl00_ContentPlaceHolder3_pe_sectionheader_]");
            for (var i = 0; i < TableRow.length; i++) {
                if (TableRow[i].id.indexOf('_1__Child') > -1) {
                    TableBody.appendChild(TableRow[i]);
                }
                else {
                    Table.appendChild(TableBody);
                    DivTable.appendChild(Table);
                    TempDiv.appendChild(DivTable);

                    DivTable = document.createElement("div");
                    DivTable.id = TableRow[i].id.replace(/ /g, "_") + "_tabs";

                    ullist += "<li><a href=\"#" + DivTable.id + "\">" + $(TableRow[i]).find("div:first-child").text() + "</a></li>";

                    Table = document.createElement("table");
                    Table.width = "100%";
                    TableBody = document.createElement('tbody');
                }
            }
            Table.appendChild(TableBody);
            DivTable.appendChild(Table);
            TempDiv.appendChild(DivTable);

            var divUl = document.createElement("ul");
            divUl.innerHTML = ullist;

            var DivTabs = document.createElement("div");
            DivTabs.id = "tabs";
            $(DivTabs).css('background', 'transparent');
            DivTabs.appendChild(divUl);
            DivTabs.appendChild(TempDiv);

            TempDiv = document.getElementById("ctl00_ContentPlaceHolder3_Page_details_cell");
            TempDiv.replaceChild(DivTabs, TempDiv.childNodes[0]);
            $("#tabs").tabs();
        }
    }
}

function ForTabsError() {
    var vm_loc = document.location.href;
    if (vm_loc.toLowerCase().indexOf("dynamicscreen.aspx") > -1) {
        if ($("#ctl00_ContentPlaceHolder3_hfSectionsAsTabs").val().toLowerCase() == "true") {
            //$("#tabs").tabs('select', 0);
            if ($("#ctl00_ContentPlaceHolder3_lbl_message").html() == "") {
                $("#ctl00_ContentPlaceHolder3_lbl_message").html("<div class=\"mbErrorMessage\"><img id=\"imgInfo\" src=\"Images/info.gif\" alt=\"Information\" /> &nbsp;Provide value for required field(s).</div>");
                $("#ctl00_ContentPlaceHolder3_lbl_message").slideDown("fast").delay(5000).slideUp("fast");
            }
            else
                $("#ctl00_ContentPlaceHolder3_lbl_message").slideDown("fast").delay(5000).slideUp("fast");
        }
    }
}
/************* End of Section as Tabs ***************/